import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login/Login.vue'
import move from '../views/Login/move.vue'  // 滑块测试
import Home from '../views/admin/Home.vue'
import changePwd from "../views/admin/changePwd.vue"  // 修改密码
import addCourse from "../views/admin/addCourse.vue"  // 添加课程
import addOutline from "../views/admin/addOutline.vue"  // 添加课程大纲
import listCourse from "../views/admin/listCourse.vue"  // 课程管理
import addCollege from "../views/admin/addCollege.vue"  // 添加学院
import addMajor from "../views/admin/addMajor.vue" // 添加专业
import addTeacher from "../views/admin/addTeacher.vue"  // 添加教师
import addStudent from "../views/admin/addStudent.vue"  // 添加学生


Vue.use(VueRouter)

const routes = [
  {path: '/', redirect: "/login"},
  {path: "/login", component: Login},
  {path: "/move", component: move},
  {path: "/admin", component: Home,
    children:[
      {path: "/changePwd", component: changePwd},
      {path: "/addCourse", component: addCourse},
      {path: "/addOutline", component: addOutline},
      {path: "/listCourse", component: listCourse},
      {path: "/addCollege", component: addCollege},
      {path: "/addMajor", component: addMajor},
      {path: "/addTeacher", component: addTeacher},
      {path: "/addStudent", component: addStudent},
  ]}
]

const router = new VueRouter({
  routes
})

// 登录的时候不能跳转, 出现问题的时候使用
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(localhost, onResolve, onReject) {
  if(onResolve || onReject) return originalPush.call(this, localhost, onResolve, onReject)
  return originalPush.call(this, localhost).catch(err => err)
}

export default router
